﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NumericalMethod
{
    public partial class BinaryOperation : ContentPane
    {
        private StatusForm mStatus;
        public BinaryOperation()
        {
            InitializeComponent();
        }

        string[] operation = new string[4] { 
           "+", 
           "-", 
           "x",
           "÷"           
        };

        public override void OnLoad()
        {
            mStatus = new StatusForm();
            Parent.Controls.Add(mStatus);
            prepareData();
            mStatus.HidePanel(2);
        }

        private void prepareData()
        {
            LoadValuesOperationCombobox();
        }
        private void LoadValuesOperationCombobox()
        {
            cboOperator.Items.Clear();
            cboOperator.Items.AddRange(operation);
            cboOperator.SelectedIndex = 0;
        }

        void txtInput1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (!Numbers.IsBinaryNumber(e.KeyChar.ToString()) && e.KeyChar != '\b')
                e.Handled = true;
        }

        void txtInput2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
        {
            if (!Numbers.IsBinaryNumber(e.KeyChar.ToString()) && e.KeyChar != '\b')
                e.Handled = true;
        }
        private void btnAnswer_Click(object sender, EventArgs e)
        {
            if (txtInput1.Text.Trim() != "" && txtInput2.Text.Trim() != "")
            {
                lblAnswer.Text = Numbers.GetBinaryOperation(decimal.Parse(txtInput1.Text),
                    decimal.Parse(txtInput2.Text), cboOperator.Text);

                mStatus.AppendOutput(txtInput1.Text + cboOperator.Text + txtInput2.Text + " = " + lblAnswer.Text);
            }
        }
    }
}
